/**
 * @(#)OrderCartDao.java, 2018/2/2.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.wangzx.exercise.enums.BuyStateType;
import org.wangzx.exercise.meta.po.OrderCart;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Repository("orderCartDao")
public class OrderCartDao extends AbstractDao<OrderCart> {
    public OrderCart getById(long id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        return sqlSessionTemplate.selectOne(classStr + ".getById", map);
    }

    public List<OrderCart> getByBuyAndState(long buyerId, BuyStateType buyStateType) {
        Map<String, Object> map = new HashMap<>();
        map.put("buyer", buyerId);
        map.put("state", buyStateType.getValue());
        return sqlSessionTemplate.selectList(classStr + ".getByBuyAndState", map);
    }

    public OrderCart getByBuyAndItemId(long buyerId, long itemId) {
        Map<String, Object> map = new HashMap<>();
        map.put("buyer", buyerId);
        map.put("itemId", itemId);
        return sqlSessionTemplate.selectOne(classStr + ".getByBuyAndItemId", map);
    }

    public boolean updateOrderCart(OrderCart orderCart) {
        return sqlSessionTemplate.update(classStr + ".updateOrderCart", orderCart) > 0;
    }
}
